#include"tcplink.h"

int tcplink(const char *ip,const char *port, int *psocketfd){
    *psocketfd=socket(AF_INET,SOCK_STREAM,0);
    struct sockaddr_in addr;
    addr.sin_family=AF_INET;
    addr.sin_addr.s_addr=inet_addr(ip);
    addr.sin_port=htons(atoi(port));
    int reuse=1;
    int ret = setsockopt(*psocketfd,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(reuse));
    ERROR_CHECK(ret, -1, "setsockopt");
    ret = bind(*psocketfd, (struct sockaddr *)&addr, sizeof(addr));
    ERROR_CHECK(ret, -1, "bind");
    ret = listen(*psocketfd,MAX_LINK_POOL_VOLUME);
    ERROR_CHECK(ret, -1, "listen");
    printf("TCP监听启动成功->%s %s\n",ip,port);
    return 0;
}